package com.cat.dataStructure;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/number-of-boomerangs/description/
 * @create 2025/8/15 15:55
 * @since JDK17
 */

public class Solution17 {
    static HashMap<Long, Integer> pre = new HashMap<>();
//    static HashMap<Long, Integer> suf = new HashMap<>();
    public long f(int x1, int y1, int x2, int y2) {
        return ((long)x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }
    public int numberOfBoomerangs(int[][] points) {
        int n = points.length - 1, ans = 0;
        long t;
        for (int i = 1, cnt; i < n; i++) {
            pre.clear();
//            suf.clear();
            for (int j = 0; j < i; j++) {
                t = f(points[j][0], points[i][0], points[j][1], points[i][1]);
                pre.put(t, pre.getOrDefault(t, 0) + 1);
            }
            for (int j = i + 1; j < n; j++) {
                t = f(points[j][0], points[i][0], points[j][1], points[i][1]);
                ans += pre.getOrDefault(t, 0);
            }
        }

        return ans;
    }
}
